//
//  SearchActionView.m
//  WuJieLive
//
//  Created by haidong on 2017/12/25.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "SearchActionView.h"

@interface SearchActionView ()

@property (strong, nonatomic)HDButton *keywordBtn;
@property (strong, nonatomic)HDButton *actionBtn;

@end

@implementation SearchActionView

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self commonInit];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self commonInit];
    }
    return self;
}

- (CGSize)intrinsicContentSize {
    return CGSizeMake(kScreenWidth - 100, 30);
}

- (void)commonInit {
    self.backgroundColor = Color(237, 237, 237);
    [self setCorner:15.f];
    [self addSubview:self.keywordBtn];
    [self addSubview:self.actionBtn];
    WS(weakSelf)
    [self.keywordBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.centerY.mas_equalTo(weakSelf.mas_centerY);
        make.height.mas_equalTo(30);
    }];
    [self.actionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(weakSelf);
    }];
}

- (void)changeThemeStyleWhite {
    [self.keywordBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.keywordBtn setImage:[UIImage imageNamed:@"icon_nav_搜索"] forState:UIControlStateNormal];
    [self.keywordBtn mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
    }];
}

- (void)bindSearchKeyword:(NSString *)keywordStr {
    [self.keywordBtn setTitle:keywordStr forState:UIControlStateNormal];
}

- (void)searchAction:(id)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(viewActionWithView:tag:data:)]) {
        [self.delegate viewActionWithView:self tag:0 data:nil];
    }
}

- (HDButton *)keywordBtn {
    if (!_keywordBtn) {
        _keywordBtn = [HDButton buttonWithType:UIButtonTypeCustom];
        [_keywordBtn setImage:[UIImage imageNamed:@"icon_nav_搜索"] forState:UIControlStateNormal];
        _keywordBtn.titleLabel.font = FontSize(13.f);
        [_keywordBtn setTitleColor:ColorFromRGB(0x999999) forState:UIControlStateNormal];
        [_keywordBtn setTitle:@"搜索" forState:UIControlStateNormal];
        [_keywordBtn setImageTextDistance:5.f];
    }
    return _keywordBtn;
}

- (HDButton *)actionBtn {
    if (!_actionBtn) {
        _actionBtn = [HDButton buttonWithType:UIButtonTypeCustom];
        _actionBtn.backgroundColor = [UIColor clearColor];
        [_actionBtn addTarget:self action:@selector(searchAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _actionBtn;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
